<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-新建${name_china}</title>
 <%@include file="/common/head.jsp" %>
<style>
.btn-save{
		 background-color: #02d1cf;
  		  color: #fff;
	}
.showWay{
	width:600px;margin-left:auto;margin-right:auto;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>新建${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="addForm" method="post">
  <div id="left" class="showWay">
	 <div class="form-wrapper">
		
	     <div class="form-cont">
	        <p class="form-cont-title">店铺名</p>
	        <input type="hidden" id="storeName" name="storeName" class="summer-input summer-validatebox"/>
	        <input type="hidden" id="num" name="num" class="summer-input summer-validatebox"/> 
	        <input type="text" id="storeName0" name="storeName0" class="summer-input summer-validatebox"/> 
	     	<a id="addStore" >添加备选名称</a>
	     </div>
	     
	     <div id="addArea" class="form-cont">
	     </div>
	      <div class="form-cont">
	        <p class="form-cont-title">店铺地址</p>
	        <input type="text" id="storeAddr" name="storeAddr" class="summer-input summer-validatebox"/> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title">联系人</p>
	        <input type="text" id="storeOwner" name="storeOwner" class="summer-input"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">手机号</p>
	        <input type="text" id="phone" name="phone" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[11]']"/> 
	        <a class="btn btn-save" id="getCode">获取验证码</a>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">验证码</p>
	        <input type="text" id="code" name="code" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[6]']"/> 
	     </div>
	     
	 <div class="form-btn-wrapper" id="funcbar">
        <a class="btn btn-save" id="applyXcx">保存</a>
        <a class="btn btn-normal" id="backBtn">关闭</a>
    </div>
  </div>
  </div>
	
</form>
<script>
    var  i=1,
    	 permission = CommonUtil.getPermission('${name_english}');
    $(function () {
    	
    	//保存按钮
    	$('#funcbar').on('click',submit);
    	$("#getCode").on('click',getCode);
    	//返回按钮
    	$('#backBtn,#goBack').on('click',backMain);
    	$("#addArea").hide();
    	var count = 0;
    	$("#addStore").on('click',function(){
    		$("#addArea").show();
    		var html = '<input type="text" id="storeName'+i+'" name="storeName'+i+'" class="summer-input summer-validatebox"/> '
    		$("#addArea").append(html);
    		count = i++;
    		$("#num").val(count);
    	});
    });
    //获取验证码
    function getCode(){
    	var phone = $("#phone").val();
    	$.ajax({
			   url: CONST_URL.GET_CODE,//请求的后台地址
			   data:{
					"phone":trimSpace(phone)
				},//前台传给后台的参数
			   success: function(data){//msg:返回值
			     console.log(data);
				 if(data.msg != "null"){
					 alert(data.msg);
				 }
			   }
			});
    }
    //表单提交
    function submit(event) {
    	var storeName = "";
    	var num =  $("#num").val();
    	for(var m=0;m<=num;m++){
			if(storeName == ""){
				storeName = $('#storeName'+m+'').val();
			}else{
				storeName = storeName + ","+ $('#storeName'+m+'').val();
			}
		}
    	console.log(storeName);
    	$("#storeName").val(storeName);
    	$("#addForm").form({
        	 buttons : ['#saveBtn','#saveBtnContinue'],
             ajax: {
                 url: CONST_URL.APPLY_XCX
             },
             onSubmitSuccess: function (data) {
            	 console.log(data);
            	 if(data.msg != "null"){
            		 alert(data.msg);
            	 }else{
            		 $.stip({
       	                type:'ok',//显示类型 有info、 ok、 danger
       	                text: '保存成功！',
       	                onBeforeHide: function () {
                      		  backMain();
       	                }
                   	});
            	 }
              }
         }).form("submit");
    }
    
    //保存并继续清空form
    function resetForm(){
        //$('#xm,#zw,#cs,#bgdh,#sjhm').val('');
    }
    
    //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    
   
    //请求url
    var CONST_URL = {
    	INIT_MAIN: basePath + "${common_url}init",
       	ADD: basePath + "${common_url}add",
       	APPLY_XCX: basePath + "${common_url}applyXcx",
       	GET_CODE: basePath + "${common_url}getCode"
    };
    
</script>
</body>
</html>